package com.stone.design.mode.prototype;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

/**
 * 原型模式测试
 *
 * @author Mr_wenpan@163.com 2022/03/14 22:01
 */
public class Client {

    public static void main(String[] args) throws CloneNotSupportedException {

        List<Mail> mails = new ArrayList<>();
        Mail mail = new Mail(new MailTemplate());
        mail.setContext(UUID.randomUUID().toString());
        HashMap<String, String> map = new HashMap<>();
        map.put("123", "345");
        mail.setMap(map);

        // 需要产生大量的mail对象（并且mail对象的构造函数很复杂，new 起来很耗时，那么这里就使用原型模式了）
        for (int i = 0; i < 10000; i++) {
            Mail cloneMail = mail.clone();
            cloneMail.setAppellation("测试");
            mails.add(cloneMail);
        }

        System.out.println(mails);

        // 多线程发送邮件
        // doSendMail(mails);

    }
}
